<template>
  <div>
    <section id="bg">
    </section>
    <section class="container">
      <div>
        <h1 class="title">会员特权</h1>
        <div class="intro">
            <ul class="introList">
                <li>拥有VIP专区的功能</li>
                <li>免费收发邮件</li>
                <li>免费申请加友</li>
                <li>上传更多照片以及设定照片密码</li>
                <li>专属VIP标识</li>
                <li>访客足迹</li>
                <li>查看对方的最近登录时间</li>
            </ul>
        </div>
      </div>
      <div>
        <h1 class="title">购买区</h1>
        <div class="goodsArea">
          <div class="card" v-for="goodsLi of goodsList">
              <vipCard :item="goodsLi" :key="goodsLi.id"/>
          </div>
        </div>
      </div>
    </section>
  </div>
</template>
<script>
  import vipCard from "../widget/Card/vipCard";
  export default{
    components: {
        vipCard: vipCard
    },
    data(){
      return {
        goodsList:[
//          {
//            info:'￥30 一个月',
//            price:30,
//            type:0,
//          },
//          {
//            info:'￥55 两个月',
//            price:55,
//            type:1,
//          },
//          {
//            info:'￥80 三个月',
//            price:80,
//            type:2,
//          }
        ],
        vipStatus:'1',
      }
    },
    computed:{
      operation(){
        if(this.vipStatus){
          return '立即开通';
        }else{
          return '立即续费';
        }
      }
    },
    methods:{
      submitOrder(goodsLi){
        this.$http({
          method: 'post',
          url: 'buyVip/buy',
          data: {"id":goodsLi.id}//????
        }).then((response)=>{
          if(response.status == 'SUCCESS'){
            this.vipStatus = 1;//????????
          }else{
            this.$message({
              type:'error',
              message:this.operation+'失败！',
            });
          }
        }).catch((err)=>{
          this.$message({
            type:'error',
            message:this.operation+'失败！',
          });
        })
      },
      buying(goodsLi){
        let msg = `即将扣取账户 ${goodsLi.point} 京豆`;
        this.$confirm(msg, this.operation, {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(() => {
          this.submitOrder(goodsLi);
        });
      },
      getGoodsList(){
        this.$http({
          method: 'get',
          url: 'buyVip/list',
          params: {},
        }).then((response)=>{
          response = response.data;
          let data = response.object;
          if(response.status == 'SUCCESS'){
            this.goodsList.splice(this.goodsList.length,0,...data.objects);
          }
        }).catch((err)=>{
//        console.log('err',err);
        })
      },
//      get
    },
    created(){
      this.getGoodsList();
    }
  }
</script>
<style scoped>
  #bg{
    height:400px;
    background-image: url("../assets/vip.jpg");
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-position: top center;
    margin: 10px 150px;
  }
  .container{
    margin:10px 150px;
  }
  .title{
    margin-top: 1.5em;
    font-size: 1.2em;
    color: #f85377;
    padding-bottom: 10px;
    border-bottom: solid 2px #f85377;
  }
  .intro{
    padding: 20px;
    text-align: center;
  }
  .introList {
    text-align: center;
    list-style: none;
    line-height: 30px
  }
  .goodsArea{
    display: flex;
    flex-wrap:wrap;
    justify-content: space-around;
  }
  /*.goods{*/
    /*display: inline-flex;*/
    /*flex-wrap: wrap;*/
    /*justify-content: center;*/
    /*align-content: space-around;*/
    /*width: 10em;*/
    /*height: 7em;*/
    /*padding: 1.5em 0em;*/
    /*border-radius: 1em;*/
    /*background-color: #fef9e6;*/
    /*text-align: center;*/
  .card {
    margin: 10px;
  }
  .card:hover {
    box-shadow: 2px 2px 12px rgba(0,0,0,.12);
    transition: box-shadow 0.15s;
  }
</style>